package work.xkong.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import work.xkong.common.ResponseRest;
import work.xkong.entity.Student;
import work.xkong.entity.Teacher;
import work.xkong.entity.Teacher;
import work.xkong.mapper.TeacherMapper;
import work.xkong.service.ITeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import work.xkong.vo.inputvo.TeacherCourseSaveInputVo;
import work.xkong.vo.outputvo.CourseTableTime;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author NuanYang
 * @since 2022-11-21
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements ITeacherService {
    @Autowired
    private TeacherMapper teacherMapper;

    @Override
    public ResponseRest login(String username, String password) {
        LambdaQueryWrapper<Teacher> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Teacher::getTeacherNumber, username);

        Teacher teacher = teacherMapper.selectOne(lqw);

        if (teacher != null && teacher.getTeacherPassword().equals(password)){
            return ResponseRest.creatSuccess("恭喜你登录成功",teacher);
        }

        return ResponseRest.creatFail("账号或密码错误，请重新登录");
    }

    @Override
    public ResponseRest saveCourse(TeacherCourseSaveInputVo inputVo) {
        //判断学生是否存在
        Teacher teacher = teacherMapper.selectOne(new LambdaQueryWrapper<Teacher>().eq(Teacher::getTeacherId, inputVo.getId()));
        if (teacher == null) {
            return ResponseRest.creatFail("该教师不存在，非法请求");
        }

        boolean res = teacherMapper.saveCourse(inputVo) > 0;

        return res ? ResponseRest.creatSuccess("打分成功") : ResponseRest.creatFail("打分失败");
    }
}
